package org.huifei.a8_dynamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * @author: huifei
 * @date: 2017-08-30 15:29
 */
public class Test {

    public static void main(String[] args) {

        /*RealSubject realSubject = new RealSubject();
        InvocationHandler handler = new DynamicSubject(realSubject);
        Subject subject = null;
        subject = (Subject) Proxy.newProxyInstance(Subject.class.getClassLoader(), new Class[] {Subject.class}, handler);
        subject.request();*/

        RealSubject realSubject = new RealSubject();
        InvocationHandler handler = new DynamicSubject(realSubject);
        Class<?> clazz = handler.getClass();
        Subject subject = (Subject) Proxy.newProxyInstance(clazz.getClassLoader(), realSubject.getClass().getInterfaces(), handler);
        subject.request();
    }
}
